#!/usr/bin/env python
# -*- coding:utf8 -*-
# uncompyle6 version 2.15.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, Jul  1 2017, 13:36:56) 
# [GCC 4.4.6 20110731 (Red Hat 4.4.6-4)]
# Embedded file name: ./esb/components/component.py
# Compiled at: 2017-11-16 15:44:28
"""
Tencent is pleased to support the open source community by making 蓝鲸智云(BlueKing) available.
Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
"""
from common.base_loggers import BasicRequestLogger
from esb.component import BaseComponent
from esb.bkauth.models import User, AnonymousUser
from esb.channel import ApiChannel
from esb.bkauth.validators import UserAuthValidator
from esb.bkapp.validators import AppAuthValidator, AppCodeWhiteListValidator

class ApiChannelForAPIS(ApiChannel):
    request_loggers = [
     BasicRequestLogger()]
    request_validators = [
     AppAuthValidator(),
     UserAuthValidator()]


class ESBApiChannelForAPIS(ApiChannel):
    request_validators = [
     AppAuthValidator(),
     AppCodeWhiteListValidator(('bk_paas', 'bk_console'))]


class FTAApiChannelForAPIS(ApiChannel):
    request_loggers = [
     BasicRequestLogger()]
    request_validators = []


class Component(BaseComponent):
    """Component class"""

    def get_current_user(self):
        """获取当前用户
        """
        if not self.request.wsgi_request:
            return AnonymousUser()
        username = self.request.wsgi_request.g.get('current_user_username')
        if username:
            return User(username)
        return AnonymousUser()


class SetupConfMixin(object):

    def setup_conf(self, conf):
        self.__dict__.update(conf)
